package cn.lbaicai.service.imp;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Transformer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.lbaicai.dao.RoleDao;
import cn.lbaicai.entity.RequestData;
import cn.lbaicai.entity.ResultData;
import cn.lbaicai.entity.Role;
import cn.lbaicai.service.RoleService;
@Service
public class RoleServiceImp implements RoleService {
	@Autowired
	private RoleDao roleDao;
	public int deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return roleDao.deleteByPrimaryKey(id);
	}
	public int delAllRole(String id) {
		List<String> ids =Arrays.asList(id.split(","));
		List<Integer> newIds= new ArrayList<Integer>();
		CollectionUtils.collect(ids, new Transformer() {
			
			public Object transform(Object input) {
				// TODO Auto-generated method stub
				return Integer.valueOf((String) input);
			}
		},newIds);
		// TODO Auto-generated method stub
		return roleDao.delAllRole(newIds);
	}
	public int insert(Role record) {
		// TODO Auto-generated method stub
		return roleDao.insert(record);
	}

	public int insertSelective(Role record) {
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		record.setCreated(sf.format(new Date()));
		return roleDao.insertSelective(record);
	}

	public Role selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return roleDao.selectByPrimaryKey(id);
	}

	public int updateByPrimaryKeySelective(Role record) {
		// TODO Auto-generated method stub
		return roleDao.updateByPrimaryKeySelective(record);
	}

	public int updateByPrimaryKey(Role record) {
		// TODO Auto-generated method stub
		return roleDao.updateByPrimaryKey(record);
	}

	public List<Role> selectByRole(Role record) {
		// TODO Auto-generated method stub
		return roleDao.selectByRole(record);
	}

	public ResultData<List<Role>> selectRole(RequestData<Role> record) {
		ResultData<List<Role>> resultData = new ResultData<List<Role>>();
		// TODO Auto-generated method stub
		List<Role> lRole = roleDao.selectByQuestData(record);
		if(lRole.size()>0){
			resultData.setCode(200);
			resultData.setMsg("查询成功");
			resultData.setData(lRole);
			int count = roleDao.selectCountByQuestData(record);
			resultData.setCount(String.valueOf(count));
		}else{
			resultData.setCode(201);
			resultData.setMsg("未查到相应数据");
		}
		return resultData;
	}

}
